from django.contrib import admin

# Register your models here.
from article.models import CategoryClass, CategoryTag, Comment, UpAndDown, Article, ArticleToTag
from libs.CommonAdmin import BaseModelAdmin


@admin.register(Article)
class ArticleAdmin(admin.ModelAdmin):
    def display_content(self, obj):
        return obj.content[:20]

    def display_desc(self, obj):
        return obj.desc[:10]

    display_content.short_description = '文章内容'
    display_desc.short_description = '文章摘要'
    list_display = ['id', 'title', 'display_desc', 'up_num', 'down_num', 'comment_num', 'display_content',
                    'create_time', 'update_time', 'blog', 'category']


@admin.register(CategoryClass)
class CategoryClassAdmin(admin.ModelAdmin):
    ordering = ["id"]
    list_display = ['id', 'name', 'blog',]


@admin.register(CategoryTag)
class CategoryTagAdmin(admin.ModelAdmin):
    ordering = ["id"]
    list_display = ['id', 'name', 'blog',]


@admin.register(ArticleToTag)
class CategoryTagAdmin(admin.ModelAdmin):
    ordering = ["id"]
    list_display = ['id', 'article', 'tag']


@admin.register(UpAndDown)
class UpAndDownAdmin(admin.ModelAdmin):
    ordering = ["id"]
    list_display = ['id', 'user', 'article', 'up_or_down', 'create_time', 'update_time']


@admin.register(Comment)
class CommentAdmin(admin.ModelAdmin):
    ordering = ["id"]
    list_display = ['id', 'user', 'article', 'content', 'is_deleted', 'parent', 'create_time','update_time']
